import java.util.Arrays;

public class project {
    public int[] getStrongest(int[] arr, int k) {
        int len=arr.length;
        Arrays.sort(arr);
        int mid=arr[(len-1)/2];
        int left=0;
        int right=len-1;
        int index=0;
        int[] nums=new int[k];
        while (index<k){
            if(Math.abs(arr[left]-mid)>Math.abs(arr[right]-mid)){
                nums[index]=arr[left];
                index++;
                left++;
            }else if(Math.abs(arr[left]-mid)<=Math.abs(arr[right]-mid)){
                nums[index]=arr[right];
                index++;
                right--;
            }
        }
        return nums;
    }






















    public int flipLights(int n, int presses) {
        n=Math.min(n,3);
        if(presses==0){
            return 1;
        }
        if(presses==1){
            return n==1?2:n==2?3:4;
        }
        if(presses==2){
            return n==1?2:n==2?4:7;
        }
        return n==1?2:n==2?4:8;
    }














    public String orderlyQueue(String s, int k) {
        if(k==1 ){
            String tmp=s;
            for(int i=0;i<s.length();i++){
                String S=s.substring(i)+s.substring(0,i);
                if(S.compareTo(tmp)<0){
                    tmp=S;
                }
            }
            return tmp;
        }else{
            char[] ch=s.toCharArray();
            Arrays.sort(ch);
            return new String(ch);
        }
    }














    public int numRescueBoats(int[] people, int limit) {
        Arrays.sort(people);
        int sum=0;
        int left=0;
        int right=people.length-1;
        while (left<=right){
            if(people[left]+people[right]<=limit){
                left++;
            }
            sum++;
            right--;
        }
        return sum;
    }














    public boolean reachingPoints(int sx, int sy, int tx, int ty) {
        while(tx>sx&&ty>sy&&tx!=ty){
            if(tx>ty){
                tx%=ty;
            }else{
                ty%=tx;
            }
        }
        if(sx==tx&&ty==sy){
            return true;
        }else if(sx==tx){
            return ty>sy&&(ty-sy)%tx==0;
        }else if(sy==ty){
            return tx>sx&&(tx-sx)%ty==0;
        }else{
            return false;
        }
    }
}
